package movee.utils.crypto;

import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

/**
 *
 *
 * @author movee
 */
@Slf4j
public class GzipUtils {

    public void unGzipFile(String srcFile, String dstSuffix) throws IOException {
        FileInputStream fin = new FileInputStream(srcFile);
        GZIPInputStream gzin = new GZIPInputStream(fin);
        String dstFile = srcFile.substring(0, srcFile.lastIndexOf('.')) + dstSuffix;
        FileOutputStream fout = new FileOutputStream(dstFile);

        int count;
        byte[] buf = new byte[1024 * 1024];

        while ((count = gzin.read(buf, 0, buf.length)) != -1) {
            fout.write(buf, 0, count);
        }

        gzin.close();
        fout.close();
        fin.close();

    }


}
